package com.exia.android.socialnet;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.TabHost;

import com.exia.android.socialnet.R;
import com.exia.android.socialnet.facebook.FacebookActivity;
import com.exia.android.socialnet.linkedin.LinkedInActivity;
import com.exia.android.socialnet.twitter.TwitterActivity;

public class SocialNet extends TabActivity {
	@Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
    	setContentView(R.layout.main2);

        final Resources res = getResources(); // Resource object to get Drawables
        final TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab
        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, FacebookActivity.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec(res.getString(R.string.facebook_tab_id)).setIndicator("",
                          res.getDrawable(R.drawable.facebook_tab))
                      .setContent(intent);
        tabHost.addTab(spec);
        // Do the same for the other tabs
        intent = new Intent().setClass(this, TwitterActivity.class);
        spec = tabHost.newTabSpec("Twitter").setIndicator("",
                          res.getDrawable(R.drawable.twitter_tab))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, LinkedInActivity.class);
        spec = tabHost.newTabSpec("LinkedIn").setIndicator("",
                          res.getDrawable(R.drawable.linkedin_tab))
                      .setContent(intent);
        tabHost.addTab(spec);
        ViewGroup.MarginLayoutParams layout_l;
        layout_l = (MarginLayoutParams) tabHost.getTabWidget().getChildTabViewAt(0).getLayoutParams();
        layout_l.setMargins(0, 0, 0, 0);
        tabHost.getTabWidget().getChildTabViewAt(0).setLayoutParams(layout_l);
        tabHost.getTabWidget().getChildTabViewAt(0).setPadding(0, 0, 0, 0);
        layout_l = (MarginLayoutParams) tabHost.getTabWidget().getChildTabViewAt(1).getLayoutParams();
        layout_l.setMargins(0, 0, 0, 0);
        tabHost.getTabWidget().getChildTabViewAt(1).setLayoutParams(layout_l);
        tabHost.getTabWidget().getChildTabViewAt(1).setPadding(0, 0, 0, 0);
        layout_l = (MarginLayoutParams) tabHost.getTabWidget().getChildTabViewAt(2).getLayoutParams();
        layout_l.setMargins(0, 0, 0, 0);
        tabHost.getTabWidget().getChildTabViewAt(2).setLayoutParams(layout_l);
        tabHost.getTabWidget().getChildTabViewAt(2).setPadding(0, 0, 0, 0);
        tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
			
			@Override
			public void onTabChanged(String tabId) {
				if(tabId.equals(res.getString(R.string.facebook_tab_id))){
					tabHost.getCurrentTabView().setBackgroundColor(res.getColor(R.color.facebook_dark_blue));
					tabHost.getTabWidget().getChildTabViewAt(1).setBackgroundColor(res.getColor(R.drawable.black));
					tabHost.getTabWidget().getChildTabViewAt(2).setBackgroundColor(res.getColor(R.drawable.black));
				}else if(tabId.equals(res.getString(R.string.twitter_tab_id))){
					tabHost.getCurrentTabView().setBackgroundColor(res.getColor(R.color.twitter_blue));
					tabHost.getTabWidget().getChildTabViewAt(0).setBackgroundColor(res.getColor(R.drawable.black));
					tabHost.getTabWidget().getChildTabViewAt(2).setBackgroundColor(res.getColor(R.drawable.black));
				}else if(tabId.equals(res.getString(R.string.linkedin_tab_id))){
					tabHost.getCurrentTabView().setBackgroundColor(res.getColor(R.color.linkedin_blue));
					tabHost.getTabWidget().getChildTabViewAt(0).setBackgroundColor(res.getColor(R.drawable.black));
					tabHost.getTabWidget().getChildTabViewAt(1).setBackgroundColor(res.getColor(R.drawable.black));
				}
			}
		});
        tabHost.setCurrentTab(0);
        tabHost.getTabWidget().getChildTabViewAt(0).setBackgroundColor(getResources().getColor(R.color.facebook_dark_blue));
	}
}
